package com.zwps.common.controller.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;

import com.zwps.common.core.context.LoginInfoContext;
import com.zwps.common.core.context.LoginedMarkContext;
import com.zwps.common.core.mybatis.interceptor.ThreadLocalOnceScopeDataInterceptor;
import com.zwps.common.core.mybatis.interceptor.ThreadLocalScopeDataInterceptor;
import com.zwps.common.core.tool.AutowiredBeanTool;
import com.zwps.common.mybatis.context.ThreadLocalSkipDataPermissionContext;

public class LoginInfoContextClearInterceptor implements HandlerInterceptor {

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        LoginedMarkContext.clear();
        LoginInfoContext.clear();

        try {
            ThreadLocalOnceScopeDataInterceptor threadLocalOnceScopeDataInterceptor = AutowiredBeanTool
                    .getBean(ThreadLocalOnceScopeDataInterceptor.class);
            if (threadLocalOnceScopeDataInterceptor != null) {
                threadLocalOnceScopeDataInterceptor.clear();
            }
        } catch (Exception e) {
        }

        try {
            ThreadLocalScopeDataInterceptor threadLocalScopeDataInterceptor = AutowiredBeanTool
                    .getBean(ThreadLocalScopeDataInterceptor.class);
            if (threadLocalScopeDataInterceptor != null) {
                threadLocalScopeDataInterceptor.clear();
            }
        } catch (Exception e) {
        }
        
        ThreadLocalSkipDataPermissionContext.clear();
    }
}
